package com.ningxun.rms.web.controller.bus;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ningxun.rms.common.annotation.DataScope;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ningxun.rms.common.annotation.Log;
import com.ningxun.rms.common.core.controller.BaseController;
import com.ningxun.rms.common.core.domain.AjaxResult;
import com.ningxun.rms.common.enums.BusinessType;
import com.ningxun.rms.domain.busrequire.BusRequire;
import com.ningxun.rms.service.baserequire.IBusRequireService;
import com.ningxun.rms.common.utils.poi.ExcelUtil;
import com.ningxun.rms.common.core.page.TableDataInfo;

/**
 * 岗位需求发布Controller
 * 
 * @author rms
 * @date 2025-07-15
 */
@RestController
@RequestMapping("/bus/require")
public class BusRequireController extends BaseController
{
    @Autowired
    private IBusRequireService busRequireService;

    /**
     * 查询岗位需求发布列表
     */
    @PreAuthorize("@ss.hasPermi('bus:require:list')")
    @DataScope(deptAlias = "b")
    @GetMapping("/list")
    public TableDataInfo list(BusRequire busRequire)
    {
        try {
            startPage();
            List<BusRequire> list = busRequireService.selectBusRequireList(busRequire);
            return getDataTable(list);
        } finally {
            // 确保分页参数被清理，避免影响其他查询
            clearPage();
        }
    }

    /**
     * 导出岗位需求发布列表
     */
    @PreAuthorize("@ss.hasPermi('bus:require:export')")
    @Log(title = "岗位需求发布", businessType = BusinessType.EXPORT)
    @DataScope(deptAlias = "b")
    @PostMapping("/export")
    public void export(HttpServletResponse response, BusRequire busRequire)
    {
        // 导出时清除分页参数，获取所有数据
        clearPage();
        List<BusRequire> list = busRequireService.selectBusRequireForExport(busRequire);
        ExcelUtil<BusRequire> util = new ExcelUtil<BusRequire>(BusRequire.class);
        util.exportExcel(response, list, "岗位需求发布数据");
    }

    /**
     * 获取岗位需求发布详细信息
     */
    @PreAuthorize("@ss.hasPermi('bus:require:query')")
    @GetMapping(value = "/{requireId}")
    public AjaxResult getInfo(@PathVariable("requireId") Long requireId)
    {
        return success(busRequireService.selectBusRequireByRequireId(requireId));
    }

    /**
     * 新增岗位需求发布
     */
    @PreAuthorize("@ss.hasPermi('bus:require:add')")
    @Log(title = "岗位需求发布", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody @Validated BusRequire busRequire)
    {
        return toAjax(busRequireService.insertBusRequire(busRequire));
    }

    /**
     * 修改岗位需求发布
     */
    @PreAuthorize("@ss.hasPermi('bus:require:edit')")
    @Log(title = "岗位需求发布", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody @Validated BusRequire busRequire)
    {
        return toAjax(busRequireService.updateBusRequire(busRequire));
    }

    /**
     * 删除岗位需求发布
     */
    @PreAuthorize("@ss.hasPermi('bus:require:remove')")
    @Log(title = "岗位需求发布", businessType = BusinessType.DELETE)
	@DeleteMapping("/{requireIds}")
    public AjaxResult remove(@PathVariable Long[] requireIds)
    {
        return toAjax(busRequireService.deleteBusRequireByRequireIds(requireIds));
    }
}
